package com.ruoyi.web.controller.study_path.controller;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.controller.study_path.domain.ARoute;
import com.ruoyi.web.controller.study_path.service.IARouteService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 路径管理Controller
 *
 * @author ruoyi
 * @date 2025-05-05
 */
@RestController
@RequestMapping("/study_path/path")
public class ARouteController extends BaseController
{
  @Autowired
  private IARouteService aRouteService;

  /**
   * 查询路径管理列表
   */
  @PreAuthorize("@ss.hasPermi('study_path:path:list')")
  @GetMapping("/list")
  public TableDataInfo list(ARoute aRoute)
  {
    startPage();
    List<ARoute> list = aRouteService.selectARouteList(aRoute);
    return getDataTable(list);
  }

  /**
   * 导出路径管理列表
   */
  @PreAuthorize("@ss.hasPermi('study_path:path:export')")
  @Log(title = "路径管理", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, ARoute aRoute)
  {
    List<ARoute> list = aRouteService.selectARouteList(aRoute);
    ExcelUtil<ARoute> util = new ExcelUtil<ARoute>(ARoute.class);
    util.exportExcel(response, list, "路径管理数据");
  }

  /**
   * 获取路径管理详细信息
   */
  @PreAuthorize("@ss.hasPermi('study_path:path:query')")
  @GetMapping(value = "/{routeId}")
  public AjaxResult getInfo(@PathVariable("routeId") Long routeId)
  {
    return success(aRouteService.selectARouteByRouteId(routeId));
  }

  /**
   * 新增路径管理
   */
  @PreAuthorize("@ss.hasPermi('study_path:path:add')")
  @Log(title = "路径管理", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody ARoute aRoute)
  {
    return toAjax(aRouteService.insertARoute(aRoute));
  }

  /**
   * 修改路径管理
   */
  @PreAuthorize("@ss.hasPermi('study_path:path:edit')")
  @Log(title = "路径管理", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@RequestBody ARoute aRoute)
  {
    return toAjax(aRouteService.updateARoute(aRoute));
  }

  /**
   * 删除路径管理
   */
  @PreAuthorize("@ss.hasPermi('study_path:path:remove')")
  @Log(title = "路径管理", businessType = BusinessType.DELETE)
  @DeleteMapping("/{routeIds}")
  public AjaxResult remove(@PathVariable Long[] routeIds)
  {
    return toAjax(aRouteService.deleteARouteByRouteIds(routeIds));
  }


  @GetMapping("/getpath/{classId}")
  public String[] getpath(@PathVariable("classId") Long classId)
  {
    startPage();
    ARoute aRoute = new ARoute();
    aRoute.setClassId(classId);
    aRoute.setStudentId(getUserId());
    List<ARoute> list = aRouteService.selectARouteList(aRoute);
    String path = list.get(0).getPath();
    String[] split = path.split("--");
    System.out.println(split);
    return split;
  }
}

